package seven.test_7_18;

import java.util.Scanner;

public class TestMain2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        // 表示第 i 天结束后处于买入状态
        int[] f = new int[n];
        // 表示第 i 天结束后处于卖出状态
        int[] g = new int[n];
        f[0] = -arr[0];
        for (int i = 1; i < n; i++) {
            f[i] = Math.max(f[i - 1],g[i - 1] - arr[i]);
            g[i] = Math.max(g[i - 1], f[i - 1] + arr[i]);
        }
        System.out.println(g[n - 1]);
    }
}
